<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java内存泄漏深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 30px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 20px;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 30px 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            font-weight: 700;
            color: #667eea;
        }
        
        .info-card {
            background: white;
            border-left: 4px solid #667eea;
            padding: 20px;
            margin: 20px 0;
            border-radius: 0 8px 8px 0;
            box-shadow: 0 4px 6px rgba(0,0,0,0.05);
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 20px;
            border-radius: 12px;
            margin: 20px 0;
            box-shadow: 0 10px 20px rgba(0,0,0,0.1);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">
                <i class="fas fa-memory mr-4"></i>Java内存泄漏深度解析
            </h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto">
                掌握内存泄漏的本质，守护应用程序的健康运行
            </p>
            <div class="mt-8 flex justify-center space-x-4">
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                    <i class="fas fa-clock mr-2"></i>阅读时间：15分钟
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                    <i class="fas fa-layer-group mr-2"></i>深度技术文章
                </span>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        
        <!-- Introduction Section -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <h2 class="text-3xl font-bold mb-6 section-title">内存泄漏概述</h2>
            <p class="text-lg leading-relaxed text-gray-700 mb-6">
                <span class="drop-cap">内</span>存泄漏是开发过程中一个非常常见且棘手的问题，尤其是在长时间运行的 Java 应用程序中。简单来说，内存泄漏指的是程序在运行时持续占用内存，而这些内存无法被垃圾回收机制回收，最终导致系统内存不足、程序性能下降，甚至崩溃。
            </p>
            
            <div class="grid md:grid-cols-2 gap-6 mt-8">
                <div class="info-card">
                    <h3 class="text-xl font-semibold mb-3 text-purple-700">
                        <i class="fas fa-exclamation-triangle mr-2"></i>核心问题
                    </h3>
                    <p class="text-gray-600">
                        对象不再被使用却依然持有引用，导致垃圾回收器无法回收这些对象，系统内存被逐渐占满。
                    </p>
                </div>
                <div class="info-card">
                    <h3 class="text-xl font-semibold mb-3 text-purple-700">
                        <i class="fas fa-chart-line mr-2"></i>影响范围
                    </h3>
                    <p class="text-gray-600">
                        应用程序性能显著下降，响应时间延长，最终可能导致OutOfMemoryError异常。
                    </p>
                </div>
            </div>
        </div>

        <!-- Memory Leak Visualization -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 section-title">内存泄漏可视化</h2>
            <div class="mermaid">
                graph TD
                    A[应用程序启动] --> B[对象创建]
                    B --> C{对象是否仍在使用?}
                    C -->|是| D[保持引用]
                    C -->|否| E{是否存在引用?}
                    E -->|否| F[垃圾回收]
                    E -->|是| G[内存泄漏]
                    G --> H[内存占用增加]
                    H --> I[性能下降]
                    I --> J[OutOfMemoryError]
                    
                    style G fill:#f96,stroke:#333,stroke-width:4px
                    style J fill:#f66,stroke:#333,stroke-width:4px
            </div>
        </div>

        <!-- Common Causes -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 section-title">内存泄漏的典型原因</h2>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-xl card-hover">
                    <div class="text-purple-600 text-3xl mb-4">
                        <i class="fas fa-link"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">持有不再使用的对象引用</h3>
                    <p class="text-gray-700">
                        对象被创建后，程序没有及时清除引用，导致对象无法被垃圾回收器回收。例如在集合类中添加了对象，但对象的生命周期已结束。
                    </p>
                </div>
                
                <div class="bg-gradient-to-br from-blue-50 to-cyan-50 p-6 rounded-xl card-hover">
                    <div class="text-blue-600 text-3xl mb-4">
                        <i class="fas fa-database"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">静态集合类中的对象未释放</h3>
                    <p class="text-gray-700">
                        静态集合类在程序运行期间保持了对对象的引用，即使这些对象不再使用，这些静态集合会导致它们无法被垃圾回收。
                    </p>
                </div>
                
                <div class="bg-gradient-to-br from-green-50 to-emerald-50 p-6 rounded-xl card-hover">
                    <div class="text-green-600 text-3xl mb-4">
                        <i class="fas fa-broadcast-tower"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">事件监听器未注销</h3>
                    <p class="text-gray-700">
                        当事件监听器或回调函数注册到某个对象上时，如果在不再使用时没有及时注销，它们会继续持有对目标对象的引用。
                    </p>
                </div>
                
                <div class="bg-gradient-to-br from-orange-50 to-red-50 p-6 rounded-xl card-hover">
                    <div class="text-orange-600 text-3xl mb-4">
                        <i class="fas fa-stream"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">资源未正确释放</h3>
                    <p class="text-gray-700">
                        I/O流、数据库连接、网络连接等资源在使用完毕后未被及时关闭，导致底层资源无法释放。
                    </p>
                </div>
            </div>
        </div>

        <!-- Detection Methods -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 section-title">内存泄漏的检测方法</h2>
            
            <div class="space-y-6">
                <div class="flex items-start space-x-4">
                    <div class="flex-shrink-0 w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center">
                        <i class="fas fa-file-alt text-purple-600"></i>
                    </div>
                    <div class="flex-1">
                        <h3 class="text-xl font-semibold mb-2">JVM日志与GC日志分析</h3>
                        <p class="text-gray-700 mb-3">
                            通过开启JVM的日志功能，记录垃圾回收的活动。通过分析GC日志，可以查看哪些对象无法被回收。
                        </p>
                        <div class="code-block">
                            <code>java -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:gc.log YourApp</code>
                        </div>
                    </div>
                </div>
                
                <div class="flex items-start space-x-4">
                    <div class="flex-shrink-0 w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center">
                        <i class="fas fa-tools text-blue-600"></i>
                    </div>
                    <div class="flex-1">
                        <h3 class="text-xl font-semibold mb-2">内存分析工具</h3>
                        <div class="grid md:grid-cols-3 gap-4 mt-4">
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <h4 class="font-semibold text-purple-700 mb-2">VisualVM</h4>
                                <p class="text-sm text-gray-600">JDK自带工具，实时监控内存使用</p>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <h4 class="font-semibold text-purple-700 mb-2">Eclipse MAT</h4>
                                <p class="text-sm text-gray-600">强大的堆转储分析工具</p>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <h4 class="font-semibold text-purple-700 mb-2">JProfiler</h4>
                                <p class="text-sm text-gray-600">商业化性能分析工具</p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="flex items-start space-x-4">
                    <div class="flex-shrink-0 w-12 h-12 bg-green-100 rounded-full flex items-center justify-center">
                        <i class="fas fa-code text-green-600"></i>
                    </div>
                    <div class="flex-1">
                        <h3 class="text-xl font-semibold mb-2">Heap Dump分析</h3>
                        <p class="text-gray-700 mb-3">
                            使用jmap命令导出JVM的堆转储文件，之后可以用MAT等工具打开分析。
                        </p>
                        <div class="code